package com.cskaoyan.salary;

import com.cskaoyan.salary.bean.Employee;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/transferList")
public class TransferListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //取得employeeList.jsp页面post过来的id数组
        String[] ids = request.getParameterValues("id");
        //获得session域中的全部人员信息，通过和id的比较，确认发工资的人员，存入到toTransfer数组中
        ArrayList<Employee> toTransfer = new ArrayList<>();
        List<Employee> list = (List<Employee>) request.getSession().getAttribute("employeeList");
        //进行遍历
        for (Employee employee : list){
            for (String id : ids){
                if (Integer.parseInt(id) == employee.getId()){
                    toTransfer.add(employee);
                }
            }
        }
        //将待转账的名单传到request域
        request.setAttribute("transferList",toTransfer);
        request.getRequestDispatcher("/transfer").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
